//
//  MyDataTableViewCell.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/10/6.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "MyDataTableViewCell.h"

@implementation MyDataTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = TotalWhite;
        [self setMainView];
    }
    return self;
}

- (void)setMainView
{
    if (!self.dateLab) {
        self.dateLab = [UILabel new];
        self.dateLab.textColor = UIColorFromHex(0x999999);
        self.dateLab.font = FontMediumWithSize(12);
        self.dateLab.text = @"10.01";
        [self addSubview:self.dateLab];
    }
    if (!self.saleLab) {
        self.saleLab = [UILabel new];
        self.saleLab.textColor = titleColor;
        self.saleLab.font = FontMediumWithSize(12);
        self.saleLab.text = @"7438.00";
        self.saleLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.saleLab];
    }
    if (!self.profitLab) {
        self.profitLab = [UILabel new];
        self.profitLab.textColor = titleColor;
        self.profitLab.font = FontMediumWithSize(12);
        self.profitLab.text = @"540.00";
        self.profitLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.profitLab];
    }
    if (!self.numLab) {
        self.numLab = [UILabel new];
        self.numLab.textColor = titleColor;
        self.numLab.font = FontMediumWithSize(12);
        self.numLab.text = @"26";
        self.numLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.numLab];
    }
    if (!self.lineView) {
        self.lineView = [UIView new];
        self.lineView.backgroundColor = UIColorFromHex(0xF1F1F1);
        [self addSubview:self.lineView];
    }
 
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.dateLab.frame = CGRectMake(15, 10, 80, 17);
    self.saleLab.frame = CGRectMake(self.dateLab.right, self.dateLab.top, 0.2*self.width, 17);
    self.profitLab.frame = CGRectMake(self.saleLab.right+30, self.dateLab.top, 0.2*self.width, 17);
    self.numLab.frame = CGRectMake(self.width-55, self.dateLab.top, 40, 17);
    self.lineView.frame = CGRectMake(0, self.height-1, SCREENWIDTH, 1);
}

- (void)getData:(MyDataModel *)model
{
    self.model = model;
    self.dateLab.text = [NSString stringWithFormat:@"%@",model.periodName];
    self.saleLab.text = [NSString stringWithFormat:@"%.2f",[model.salesAmount floatValue]];
    self.profitLab.text = [NSString stringWithFormat:@"%.2f",[model.gainsAmount floatValue]];
     self.numLab.text = [NSString stringWithFormat:@"%li",model.productCount];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
